----------------
--GHOST PROFILES--
----------------

function convert(spell)
	local spell = GetSpellInfo(spell)
	return spell
end

function Cast(spell, unit)
	local spell = convert(spell)
	if IsUsableSpell(spell)
			and GetSpellCooldown(spell) == 0 then
		GHOST_CastTarget = unit 
		CastSpellByName(spell, unit)
	end
end

function StopCast(spell)
	local spell = convert(spell)
	if UnitCastingInfo("player") == spell
			or UnitChannelInfo("player") == spell then
		SpellStopCasting()
	end
end

function CanCast(spell, unit)
	local spell = convert(spell)
	local target = unit or "target"
	if UnitCanAttack("player", target)
			and PQR_UnitFacing("player", target)
			and IsSpellInRange(spell) == 1 then
		return true
	end
end

function UnitBuffCount(unit, spell, filter)
	local spell = convert(spell)
	local buff = { UnitBuff(unit, spell, nil, filter) }
	if buff[1] then
		return buff[4]
	else
		return 0
	end
end

function UnitDebuffCount(unit, spell, filter)
	local spell = convert(spell)
	local debuff = { UnitDebuff(unit, spell, nil, filter) }
	if debuff[1] then
		return debuff[4]
	else
		return 0
	end
end

function UnitBuffTime(unit, spell, filter)
	local spell = convert(spell)
	local buff = { UnitBuff(unit, spell, nil, filter) }
	if buff[1] then
		return buff[7] - GetTime()
	else
		return 0
	end
end

function UnitDebuffTime(unit, spell, filter)
	local spell = convert(spell)
	local debuff = { UnitDebuff(unit, spell, nil, filter) }
	if debuff[1] then
		return debuff[7] - GetTime()
	else
		return 0
	end
end

function UnitHP(unit)
	return UnitHealth(unit) / UnitHealthMax(unit) * 100
			or 0
end

function UnitMP(unit)
	return UnitPower(unit, 0) / UnitPowerMax(unit, 0) * 100
			or 0
end

function HasThreat(unit)
	local threat = UnitThreatSituation(unit)
	if UnitAffectingCombat("player")
			and threat then
		if threat >= 2 then
			return unit
		end
	else
		return nil
	end
end